package com.yihu.cms.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.yihu.article.beans.LoginResult;
import com.yihu.beans.user.User;
import com.yihu.cms.service.UserService;
import com.yihu.cms.util.CMSConstants;
import com.yihu.web.bean.user.Coupon;
import com.yihu.web.bean.vo.CouponQuery;
import com.yihu.web.bean.vo.CouponVO;
import com.yihu.web.bean.vo.QRCode;
import com.yihu.yihuds.service.YihuUserService;
/**
 * 
 * @author Aaron
 *
 */
@Controller
@RequestMapping("/coupon")
@SuppressWarnings("rawtypes")
public class CouponController extends BaseController{
	private final Logger logger = LoggerFactory.getLogger(CouponController.class); 
	YihuUserService service = new YihuUserService();
	//test interface
	@RequestMapping(value = "/batchAdd", method = RequestMethod.POST)
	public @ResponseBody Object batchAdd(@RequestBody Coupon coupon) {
		logger.debug("batchAdd: "+JSON.toJSONString(coupon));		
		return service.batchAddCoupons(coupon);
	}
	/***
	 * 新用户发送优惠券，暂定，50，100，200面值各一张
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/newuser", method = RequestMethod.GET)
	public @ResponseBody Object setNewuserCoupons(long userId) {	
		logger.debug("setNewuserCoupons: "+userId);	
		//return service.setNewuserCoupons(userId);
		return getResult(0,null);
	}
	
	/***
	 * 领取优惠券
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/receive", method = RequestMethod.GET)
	public @ResponseBody Object receiveCoupon(CouponVO cvo) {	
		logger.debug("receiveCoupon: "+cvo);	
	
		return service.receiveCoupon(cvo);
	}
	
	
	/***
	 * 我的优惠券
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public @ResponseBody Object couponlist(CouponQuery query) {	
		logger.debug("couponlist: "+query);	
		return service.getCouponsPage(query);
	}

	
}
